package com.sunday.volunteer.fragment.tab;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sunday.common.utils.ToastUtils;
import com.sunday.member.base.BaseFragment;
import com.sunday.volunteer.BaseApp;
import com.sunday.volunteer.R;
import com.sunday.volunteer.entity.Member;
import com.sunday.volunteer.ui.mine.GroupActivity;
import com.sunday.volunteer.ui.mine.MyActivityActivity;
import com.sunday.volunteer.ui.mine.OrderActivity;
import com.sunday.volunteer.ui.mine.PublishActivity;
import com.sunday.volunteer.ui.mine.InformationActivity;
import com.sunday.volunteer.ui.mine.UserInfoActivity;
import com.sunday.volunteer.ui.mine.VolunteerCardActivity;
import com.sunday.volunteer.utils.BaseUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Pual's PC on 2016/10/8.
 */
public class MineFragment extends BaseFragment {

    @Bind(R.id.logo)
    ImageView logo;
    @Bind(R.id.name)
    TextView name;
    @Bind(R.id.score)
    TextView score;
    @Bind(R.id.hours)
    TextView hours;
    @Bind(R.id.hours2)
    TextView hours2;
    @Bind(R.id.hours3)
    TextView hours3;
    @Bind(R.id.projects)
    TextView projects;
    @Bind(R.id.pb_progressbar)
    ProgressBar progressBar;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_mine ,null);
        ButterKnife.bind(this , rootView);
        return rootView;
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @OnClick(R.id.to_user_card)
    void toUserCard(){
        BaseUtil.openActivity(mContext ,VolunteerCardActivity.class);
    }


    @OnClick(R.id.to_user_publish)
    void toUserPublish(){
        if(BaseApp.getInstance().getMember().getUserType() != 2){
            ToastUtils.showToast(mContext , "只有高级志愿者才可以发布活动");
                return;
        }
        BaseUtil.openActivity(mContext ,PublishActivity.class);
    }

    @OnClick(R.id.to_user_activity)
    void toUserActivity(){
        BaseUtil.openActivity(mContext ,MyActivityActivity.class);
    }


    @OnClick(R.id.to_user_team)
    void toUserTeam(){
        BaseUtil.openActivity(mContext ,GroupActivity.class);
    }

    @OnClick(R.id.to_user_order)
    void toUserOrder(){
        BaseUtil.openActivity(mContext ,OrderActivity.class);
    }

    @OnClick(R.id.to_user_training)
    void toUserTraining(){
        BaseUtil.openActivity(mContext ,InformationActivity.class);
    }

    @OnClick(R.id.to_user_info)
    void toUserInfo(){
        BaseUtil.openActivity(mContext ,UserInfoActivity.class);
    }


    @Override
    public void onResume() {
        super.onResume();
    }


    public void setData(Member member){
        Picasso.with(mContext)
                .load(TextUtils.isEmpty(member.getLogo())?"http":member.getLogo())
                .placeholder(R.drawable.default_error)
                .centerCrop()
                .resize(180,180)
                .into(logo);
        name.setText(TextUtils.isEmpty(member.getName())?"小小志愿者":member.getName());
        score.setText(String.format("%.0f" ,member.getScore()));
        hours.setText(String.format("%d" ,member.getHours()));
        hours2.setText(String.format("%d" ,100 - member.getHours() ));
        hours3.setText(String.format("%d" ,member.getHours()));
        projects.setText(String.format("%d" ,member.getProjects()));
        progressBar.setProgress(member.getHours()<=5000?member.getHours():5000);
    }


}
